package info.rflow.actions;

import info.rflow.graph.RWorkflowScene;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;


/**
 * Creates a new resizable background label area within the current screen.
 *
 * @author Holger Brandl
 */
public class NewBackgroundLabelAction extends AbstractAction {

    private RWorkflowScene workflowScene;
    private Point lastLocation;


    public NewBackgroundLabelAction(RWorkflowScene workflowScene) {
        this.workflowScene = workflowScene;

        putValue(NAME, "Add Background Label Here");
        workflowScene.getView().addMouseMotionListener(new MouseMotionListener() {

            public void mouseDragged(MouseEvent e) {

            }


            public void mouseMoved(MouseEvent e) {
                lastLocation = e.getPoint();
            }
        });
    }


    public void actionPerformed(ActionEvent e) {
        // create a new background node

        assert lastLocation != null;
        workflowScene.addBckndLabel("Unnamed", lastLocation, null, null);
    }
}
